package JFrame.Admin;

import JFrame.Admin.MailManager.AddMailJFrame;
import JFrame.Admin.MailManager.AdminQueryMailJFrame;
import JFrame.Admin.MailManager.DeleteMailJFrame;
import JFrame.Admin.MailManager.ModifyMailJFrame;
import JFrame.Admin.UserManager.DeleteUserJFrame;
import JFrame.Admin.UserManager.ModifyUserJFrame;
import JFrame.Admin.UserManager.QueryUserJFrame;
import entity.Mail;
import serive.AdminService;
import serive.AdminServiceImpl;
import statics.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import JFrame.*;

/**
 * @className: AdminMainFrame
 * @description: 管理员主界面
 * @author: Dong
 * @date: 2021/12/29
 **/
public class AdminMainFrame  extends JFrame {
    JMenuBar menuBar;
    JMenu m_mail,m_user,m_bgTip;
    JMenuItem mi_queryAll, mi_modify, mi_add,mi_delete,user_queryAll,user_modify,user_delete, mi_about,mi_explain;
    AdminService adminService =new AdminServiceImpl();
    public AdminMainFrame() {
        // TODO Auto-generated constructor stub
        this.setTitle("快递派送系统——管理员");
        this.setLocationRelativeTo(null);//窗体居中显示
        init();
        //页面大小不可变
        setResizable(false);
        this.setVisible(true);
    }

    public void init() {
        this.getContentPane().setLayout(null);
        this.setSize(Data.adminMain.getIconWidth()+900, Data.adminMain.getIconHeight()+60);
        this.setLocationRelativeTo(null);//窗体居中显示

        this.getContentPane().setBounds(0,0,Data.adminMain.getIconWidth()+344, Data.adminMain.getIconHeight());
        JLabel label=new JLabel(Data.adminMain);
        label.setBounds(0,0,Data.adminMain.getIconWidth(),Data.adminMain.getIconHeight());
        this.getContentPane().add(label);
        menuBar = new JMenuBar();
        m_mail = new JMenu("快件信息");
        m_user = new JMenu("用户管理");
        m_bgTip = new JMenu("Help");
        mi_queryAll = new JMenuItem("查询所有快件");
        mi_queryAll.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new AdminQueryMailJFrame();
            }

        });

        mi_modify = new JMenuItem("快件信息修改");
        mi_modify.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               new ModifyMailJFrame();
            }
        });
        mi_add = new JMenuItem("添加快件");
        mi_add.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddMailJFrame h=new AddMailJFrame();
            }
        });
        mi_delete =new JMenuItem("删除快件");
        mi_delete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

              new DeleteMailJFrame();

            }
        });
        mi_about=new JMenuItem("关于");
        mi_about.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AboutJFrame();
            }
        });
        mi_explain=new JMenuItem("解释");
        mi_explain.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ExplainJFrame();
            }
        });
        m_mail.add(mi_queryAll);
        m_mail.addSeparator();
        m_mail.add(mi_add);
        m_mail.add(mi_delete);
        m_mail.add(mi_modify);
        m_bgTip.add(mi_about);
        m_bgTip.add(mi_explain);

        user_modify= new JMenuItem("修改用户信息");
        user_modify.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ModifyUserJFrame();
            }
        });
        user_queryAll = new JMenuItem("查询所有用户");
        user_queryAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new QueryUserJFrame();
            }
        });
        user_delete = new JMenuItem("删除用户");
        user_delete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new DeleteUserJFrame();
            }
        });
        m_user.add(user_queryAll);
        m_user.addSeparator();
        m_user.add(user_modify);
        m_user.add(user_delete);

        menuBar.add(m_mail);
        menuBar.add(m_user);
        menuBar.add(m_bgTip);

        JTextArea textArea = new JTextArea();
        textArea.setText("提醒 三天没派送的快件的快件：\n");
        textArea.setFont(new Font("宋体",1,18));
        textArea.setBackground(new Color(173, 199, 201));
        List<Mail> mailList = adminService.withoutDeliveryForThreeDays();
        if (mailList.isEmpty()){
            textArea.append("暂时没有三天没派送的快件，继续加油！！\n");
        }else {
            for (Mail mail : mailList) {
                textArea.append(mail.toString()+"\n");
            }
            textArea.append("请尽快派送 以上快件");

        }

        textArea.setBounds(Data.adminMain.getIconWidth(), 0, 900, Data.adminMain.getIconHeight());
        this.getContentPane().add(textArea);

        this.setJMenuBar(menuBar);

    }
}
class AboutJFrame extends JFrame{
    public AboutJFrame(){
        this.setLocationRelativeTo(null);//窗体居中显示
        //页面大小不可变
        setResizable(false);
        JLabel jLabel =new JLabel(Data.about);
        this.setSize(Data.about.getIconWidth()+10,Data.about.getIconHeight()+50);
        this.getContentPane().add(jLabel);
        this.setVisible(true);
    }

}
class ExplainJFrame extends JFrame{
    public ExplainJFrame(){
        //页面大小不可变
        setResizable(false);
        this.setLocationRelativeTo(null);//窗体居中显示
        this.setSize(550,500);
        JTextArea jTextArea =new JTextArea("在本系统中的一些说明:\n"+
                "1.当你看到时间是1970-01-01 00:00:00\n" +
                "  说明此时间是null 可以理解为空\n"+
                "2. 快件状态的格式有3种 已派送，未派送，派送中\n" +
                "3. 为保证安全，管理员不可注册\n" +
                    "添加管理员，请联系数据库管理者");
        Tools.setFonts(20,1,jTextArea);
        this.getContentPane().add(jTextArea);
        this.setVisible(true);
    }

}

